/**
 *  文件名:ActivityMyspace.java
 *  修改人:lihangjie
 *  创建时间:2015-9-1 上午11:26:48
 */
package com.sharemob.tinchat.modules.account;

import java.util.ArrayList;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.sharemob.tinchat.R;
import com.sharemob.tinchat.base.BaseActivityGroup;
import com.sharemob.tinchat.base.ListAdapterForPet;
import com.sharemob.tinchat.base.ParallaxScollListView;
import com.sharemob.tinchat.base.PetItem;
import com.sharemob.tinchat.lib.Blur;
import com.sharemob.tinchat.lib.ImageUtils;
import com.sharemob.tinchat.lib.Utils;

/**
 * 
 * @author lihangjie
 * version [版本号,2015-9-1 上午11:26:48]
 * @see    [相关类/方法]
 * @since  [产品/模块版本]
 *
 */
public class MyspaceActivity extends BaseActivityGroup {
	  private ParallaxScollListView mListView;
	  
		private static final int INDEX_SPACE_GIFT = 0;
		private static final int INDEX_SPACE_PHOTO = 1;
		private static final int INDEX_SPACE_PET = 2;
		private static final int INDEX_SPACE_VISITOR = 3;
		
		public void initFragment(){
			this.addFragmentManager(fragmentManager.findFragmentById(R.id.fragement_space_gift));
			this.addFragmentManager(fragmentManager.findFragmentById(R.id.fragement_space_photo));
			this.addFragmentManager(fragmentManager.findFragmentById(R.id.fragement_space_pet));
			this.addFragmentManager(fragmentManager.findFragmentById(R.id.fragement_space_visitor));
			
			hideAllFragment();
			showFragment(INDEX_SPACE_GIFT);
			
	        RadioGroup rg = (RadioGroup) findViewById(R.id.myspace_tab_group);
	        if(rg!=null){
	        	  rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
	  	            public void onCheckedChanged(RadioGroup group, int checkedId) {
	  	            	int index =3;
	  	            	switch (checkedId) {
	  					case R.id.myspace_tab_gift:
	  						 index =INDEX_SPACE_GIFT;
	  						break;
	  					case R.id.myspace_tab_photo:
	  						index =INDEX_SPACE_PHOTO;
	  						break;
	  					case R.id.myspace_tab_pet:
	  						index =INDEX_SPACE_PET;
	  						break;
	  					case R.id.myspace_tab_visitor:
	  						index =INDEX_SPACE_VISITOR;
	  						break;
	  
	  					default:
	  						break;
	  					}
	  	            	showFragment(index);
	  	            }
	  	        });
	        }
	      
		}
		
	  protected void onCreate(Bundle savedInstanceState)
	  {
	        super.onCreate(savedInstanceState);
	        requestWindowFeature(Window.FEATURE_NO_TITLE);
	        setContentView(R.layout.activity_myspace);
	        
	 
	        initListView();
	        initFragment();
	        exitView(R.id.title_back, R.anim.activity_close,0);
	    }
	 
	 public void initListView(){
	        mListView = (ParallaxScollListView) findViewById(R.id.layout_space_listview);
	        View header = LayoutInflater.from(this).inflate(R.layout.layout_myspace_header, null);
	        
	        final ImageView mImageView = (ImageView) header.findViewById(R.id.layout_header_image);
	        
	        mImageView.setOnClickListener(new OnClickListener()
	        {
	            public void onClick(View v)
	            {
	            	Utils.SelectPhotoDialog(MyspaceActivity.this);
	            }
	        });
	        
	        Bitmap sentBitmap=ImageUtils.getBitMapFromRescourceID(this, R.drawable.bg_space);
	        Bitmap bitmap_header_image=Blur.fastblur(this, sentBitmap, 8, true);
	        mImageView.setImageBitmap(bitmap_header_image);
	        
	        mListView.setParallaxImageView(mImageView);
	        mListView.addHeaderView(header);
	        ListAdapterForPet adapter=new ListAdapterForPet();
	        ArrayList<PetItem> list=new ArrayList<PetItem>();
//	        PetItem petItem=new PetItem();
//	        petItem.setIcon(R.drawable.img_integral_xiaotuan);
//	        petItem.setId("10001");
//	        petItem.setLevel(2);
//	        petItem.setName("獒犬");
//	        list.add(petItem);
	        adapter.setAdapter(list);
	        
	        mListView.setAdapter(adapter);
	 }
	 
	 
	protected void keyEventOfListView(int position, int id) {
		
	}

    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);

        if (hasFocus) {
            mListView.setViewsBounds(ParallaxScollListView.ZOOM_X2);
        }
    }

}
